#!/usr/bin/env node

const http  = require('https'),

      log   = console.log,
      url   = require('url'), 
      city = process.argv[2] || '石家庄',
      //addr = 'https%3a%2f%2fapi.66mz8.com%2fapi%2fweather.php%3flocation%3d%e7%9f%b3%e5%ae%b6%e5%ba%84';
     
      // addr = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11';
     
      addr  = 'https://api.66mz8.com/api/weather.php?location='+city;

log(addr);
log(global.encodeURI(addr));
process.exit();
let opt = url.parse(addr);
opt.headers = {
  'user-agent':'curl/7.9.0'
};
http.get(opt,(res)=>{ 

  log(`HTTP/${res.httpVersion} ${res.statusCode} ${res.statusMessage}`); 
  log(res.headers);
  let data = '';
          
  res.on('data',(chunck)=> data += chunck);

  res.on('end',()=>{ 
    log(data);
  });
});
